﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.Serialization;
using TecBaseObjects.Base;
using TecBaseObjects.Interfaces;
using TecBaseObjects.Objects;
using TecExtensions;

namespace TecBaseObjects.Models {

    public class CashSaleModel : MyBaseModel {

        #region Members

        private List<CashSaleDetailsModel> myDetails = new List<CashSaleDetailsModel>();
        private List<JobObj> myJobDetails = new List<JobObj>();
        private double grossPrice = 0.0;
        private double salePrice = 0.0;
        private double tax = 0.0;
        private int paymentMode;
        private int invoiceNo;
        private int orgKey;
        private string orgName;
        private string orgFullName;
        private string loginName;
        private DateTime orderDate;
        private DateTime saleDate;
        private DateTime writeToLiquiDate;
        private DateTime writeInvoiceToBvDate;
        private DateTime writeInvoiceToVrspDate;
        private string orderDetail;
        private bool isDirty;
        private string dlName;
        private string dlName2;
        private string dlPlz;
        private string dlOrt;
        private string dlStrasse;
        private bool useDeliveryAddress;
        private int userID;

        #endregion

        #region Constructor

        public CashSaleModel() {
            this.orderDate = DateTime.Now;
            this.paymentMode = 1;
            this.SaleDate = DateTime.Now;
        }

        public CashSaleModel(int userID)
            : this() {
            this.userID = userID;
        }

        #endregion

        #region Properties

        public int CashSaleID {
            get;
            set;
        }

        [DataMember]
        public double GrossPrice {
            get { return this.grossPrice; }
            set {
                if (this.grossPrice == value) {
                    return;
                }
                this.grossPrice = value;
                OnPropertyChanged(() => GrossPrice);
            }
        }

        [DataMember]
        public bool NoInvoice {
            get {
                if (this.invoiceNo == 0) {
                    return true;
                }
                return false;
            }
        }

        [DataMember]
        public int InvoiceNo {
            get { return this.invoiceNo; }
            set {
                if (this.invoiceNo == value) {
                    return;
                }
                this.invoiceNo = value;
                OnPropertyChanged(() => InvoiceNo);
            }
        }

        [DataMember]
        public bool IsDirty {
            get { return this.isDirty; }
            set {
                if (this.isDirty == value) {
                    return;
                }
                this.isDirty = value;
                OnPropertyChanged(() => IsDirty);
            }
        }

        public bool IsReadyForLiqui {
            get {
                bool ret = false;
                if (this.PaymentMode == 3 || this.PaymentMode == 4) {
                    ret = true;
                }
                return ret;
            }
        }

        public bool IsReadyForVrsp {
            get {
                bool ret = false;
                if (this.PaymentMode == 1 || this.PaymentMode == 2) {
                    ret = true;
                }
                return ret;
            }
        }

        [DataMember]
        public string LoginName {
            get { return this.loginName; }
            set {
                if (this.loginName == value) {
                    return;
                }
                this.loginName = value;
                OnPropertyChanged(() => LoginName);
            }
        }

        public List<CashSaleDetailsModel> MyDetails {
            get {
                return this.myDetails;
            }
        }

        public List<JobObj> MyJobDetails {
            get { return this.myJobDetails; }
            set { this.myJobDetails = value; }
        }

        [DataMember]
        public DateTime OrderDate {
            get { return this.orderDate; }
            set {
                if (this.orderDate == value) {
                    return;
                }
                this.orderDate = value;
                OnPropertyChanged(() => OrderDate);
            }
        }

        [DataMember]
        public string OrderDetail {
            get { return this.orderDetail; }
            set {
                if (this.orderDetail == value) {
                    return;
                }
                this.orderDetail = value;
                OnPropertyChanged(() => OrderDetail);
            }
        }

        [DataMember]
        public int OrgKey {
            get { return this.orgKey; }
            set {
                if (this.orgKey == value) {
                    return;
                }
                this.orgKey = value;
                OnPropertyChanged(() => OrgKey);
            }
        }

        [DataMember]
        public string OrgName {
            get { return this.orgName; }
            set {
                if (this.orgName == value) {
                    return;
                }
                this.orgName = value;
                OnPropertyChanged(() => OrgName);
            }
        }

        [DataMember]
        public string OrgFullName {
            get { return this.orgFullName; }
            set {
                if (this.orgFullName == value) {
                    return;
                }
                this.orgFullName = value;
                OnPropertyChanged(() => OrgFullName);
            }
        }

        [DataMember]
        public int PaymentMode {
            get { return this.paymentMode; }
            set {
                if (this.paymentMode == value) {
                    return;
                }
                this.paymentMode = value;
                OnPropertyChanged(() => PaymentMode);
            }
        }

        [DataMember]
        public DateTime SaleDate {
            get { return this.saleDate; }
            set {
                if (this.saleDate == value) {
                    return;
                }
                this.saleDate = value;
                OnPropertyChanged(() => SaleDate);
            }
        }

        [DataMember]
        public double SalePrice {
            get {
                return this.salePrice;
            }
            set {
                if (this.salePrice == value) {
                    return;
                }
                this.salePrice = value;
                OnPropertyChanged(() => SalePrice);
            }
        }

        [DataMember]
        public double Taxes {
            get { return this.tax; }
            set {
                if (this.tax == value) {
                    return;
                }
                this.tax = value;
                OnPropertyChanged(() => Taxes);
            }
        }

        [DataMember]
        public int UserID {
            get { return this.userID; }
            set {
                if (this.userID == value) {
                    return;
                }
                this.userID = value;
                OnPropertyChanged(() => UserID);
            }
        }

        [DataMember]
        public string DeliverName {
            get { return this.dlName; }
            set {
                if (this.dlName == value) {
                    return;
                }
                this.dlName = value;
                OnPropertyChanged(() => DeliverName);
            }
        }

        [DataMember]
        public string DeliverName2 {
            get { return this.dlName2; }
            set {
                if (this.dlName2 == value) {
                    return;
                }
                this.dlName2 = value;
                OnPropertyChanged(() => DeliverName2);
            }
        }

        [DataMember]
        public string DeliverOrt {
            get { return this.dlOrt; }
            set {
                if (this.dlOrt == value) {
                    return;
                }
                this.dlOrt = value;
                OnPropertyChanged(() => DeliverOrt);
            }
        }

        [DataMember]
        public string DeliverPlz {
            get { return this.dlPlz; }
            set {
                if (this.dlPlz == value) {
                    return;
                }
                this.dlPlz = value;
                OnPropertyChanged(() => DeliverPlz);
            }
        }

        [DataMember]
        public string DeliverStrasse {
            get { return this.dlStrasse; }
            set {
                if (this.dlStrasse == value) {
                    return;
                }
                this.dlStrasse = value;
                OnPropertyChanged(() => DeliverStrasse);
            }
        }

        [DataMember]
        public bool UseDeliveryAddress {
            get { return this.useDeliveryAddress; }
            set {
                if (this.useDeliveryAddress == value) {
                    return;
                }
                this.useDeliveryAddress = value;
                OnPropertyChanged(() => UseDeliveryAddress);
            }
        }

        [DataMember]
        public DateTime WriteToLiquiDate {
            get { return this.writeToLiquiDate; }
            set {
                if (this.writeToLiquiDate == value) {
                    return;
                }
                this.writeToLiquiDate = value;
                OnPropertyChanged(() => WriteToLiquiDate);
            }
        }

        [DataMember]
        public DateTime WriteInvoiceToBvDate {
            get { return this.writeInvoiceToBvDate; }
            set {
                if (this.writeInvoiceToBvDate == value) {
                    return;
                }
                this.writeInvoiceToBvDate = value;
                OnPropertyChanged(() => WriteInvoiceToBvDate);
            }
        }

        [DataMember]
        public DateTime WriteInvoiceToVrspDate {
            get { return this.writeInvoiceToVrspDate; }
            set {
                if (this.writeInvoiceToVrspDate == value) {
                    return;
                }
                this.writeInvoiceToVrspDate = value;
                OnPropertyChanged(() => WriteInvoiceToVrspDate);
            }
        }

        #endregion

        #region Methods

        public void AddMyDetail(CashSaleDetailsModel item) {
            this.myDetails.Add(item);
        }

        public void AddMyJobDetail(JobObj item) {
            this.myJobDetails.Add(item);
        }



        #endregion
        
    }
}
